import toolMgr from '@/biz/base/tool.js'
import dt from '@dt/dt'
import ruleOpt from '@/biz/option/rule.js'

let _this = null

function options(vm) {
  _this = vm
  let api = toolMgr.unloadFile()
  let files = []
  return [
    [
      {
        title: '请佣月份',
        key: 'commissionMonth',
        text: {}
      }
    ],
    [
      {
        title: '结算标准',
        text: {},
        data: {
          from: (info) => {
            return dt.dictInfo().__value('settlementType', info.settlementType)
          }
        }
      }
    ],
    [
      {
        title: '套数',
        text: {},
        data: {
          from: (info) => {
            return info.roomCount + '套'
          }
        }
      }
    ],
    [
      {
        title: '总金额',
        text: {},
        data: {
          from: (info) => {
            return dt.tool.formatterMoney(info.sumAmount) + '元'
          }
        }
      }
    ],
    [
      {
        title: '总面积',
        text: {},
        data: {
          from: (info) => {
            return dt.tool.formatterMoney(info.sumArea) + '㎡'
          }
        }
      }
    ],
    {
      title: '电子版附件',
      key: 'digitalAttaches',
      upload: {
        title: '附件上传',
        api,
        files,
        multiple: true,
        preview: (file) => {
          toolMgr.downloadFile(file.url, file.name)
        }
      },
      rules: [ruleOpt.required('请上传附件', 'array')],
      data: {
        to: (v) => {
          return {
            digitalAttaches: v.map((item) => {
              return {
                fileName: item.name,
                attachAddress: item.response?.data.imageURL ?? item.url
              }
            })
          }
        }
      }
    },
    [
      {
        title: '备注',
        key: 'remark',
        input: {
          type: 'textarea',
          autosize: {
            minRows: 2
          }
        },
        rules: [ruleOpt.max(1000)]
      }
    ]
  ]
}

export default {
  options
}
